/**
 * Created by Vector on 17/7/25.
 */

var express = require('express');
var app = express();
var fs = require('fs');




    // 读取已存在的数据
    app.get('/addUser', function (req, res) {

        var user = {
            "name":req.query.name,
            "password":req.query.password,
            "sex":req.query.sex,
            "age":req.query.age
        }

        // 读取已存在的数据
        fs.readFile( __dirname + "/" + "user.json", 'utf8', function (err, data) {
            data = JSON.parse( data );

            data["user4"] = user;
            console.log( data );
            res.end();
        });
    })


var server = app.listen(3000, function () {

    var host = server.address().address
    var port = server.address().port
    console.log("应用实例，访问地址为 http://%s:%s", host, port)

})
